<?php

/**
 * Subclass for performing query and update operations on the 'salarie' table.
 *
 * 
 *
 * @package lib.model
 */
class SalariePeer extends BaseSalariePeer {

  static public function getAllSalaries() {
    return BaseSalariePeer::doSelect(new Criteria());
  }

  static public function getSalariesByUserId($user_id) {
    $criteria = new Criteria(SalariePeer::DATABASE_NAME);
    $criteria->add(SalariePeer::GUARD_ID, $user_id);
    $criteria->add(SalariePeer::ACTIF, 1);

    return SalariePeer::doSelect($criteria);
  }

  static public function isSalarieIdBelongsToUserId($salarie_id, $user_id) {
    $salaries = self::getSalariesByUserId($user_id);
    foreach ($salaries as $salarie)
      if ($salarie->getId() == $salarie_id)
        return true;
    return false;
  }

  public static function getSalariesSansUf() {
    $not_in_query = '%s NOT IN (SELECT %s FROM %s)';

    $not_in_query = sprintf(
      $not_in_query, 
      SalariePeer::ID, 
      AssoSalarieUniteFonctionnellePeer::SALARIE_ID, 
      AssoSalarieUniteFonctionnellePeer::TABLE_NAME
    );


    $criteria = new Criteria();
    $criteria->add(SalariePeer::ID, $not_in_query, Criteria::CUSTOM);
    
    return SalariePeer::doSelect($criteria);
  }

}
